const query = require("../db/mysql")
const { error, success } = require("../module/module")


class Results {
    getSaleNum = async (ctx) => {
        let sql = 'select * from saleNum where 1=1 '
        let data = await query(sql)
        if (data.length) {
            ctx.body = success(data)
        }
    }
    //筛选城市
    selectcity = async (ctx) => {
        let { provinces, cities, areas } = ctx.request.body;
        let sql = `select * from buyRoom where 1=1 `
        if (provinces && cities && areas) {
            sql += `and provinces like "%${provinces}%" and cities like "%${cities}%" and areas like "%${areas}%" `
            let data = await query(sql)
            if (data.length) {
                ctx.body = success(data, '筛选成功')
            } else {
                ctx.body = error('没有相关数据')
            }
        } else if (cities && areas) {
            sql += `and cities like "%${cities}%" and areas like "%${areas}%" `
            let data = await query(sql)
            if (data.length) {
                ctx.body = success(data, '筛选成功')
            } else {
                ctx.body = error('没有相关数据')
            }
        } else if (provinces && cities) {
            sql += `and provinces like "%${provinces}%" and cities like "%${cities}%"  `
            let data = await query(sql)
            if (data.length) {
                ctx.body = success(data, '筛选成功')
            } else {
                ctx.body = error('没有相关数据')
            }
        }
    }
    getRentNum = async (ctx) => {
        let sql = 'select * from buyRoom where 1=1 '
        let data = await query(sql)
        if (data.length) {
            ctx.body = success(data)
        }
    }
    rentSelect = async (ctx) => {
        let { provinces, cities, areas } = ctx.request.body;
        let sql = `select * from saleNum where 1=1 `
        if (provinces && cities && areas) {
            sql += `and provinces like "%${provinces}%" and cities like "%${cities}%" and areas like "%${areas}%" `
            let data = await query(sql)
            if (data.length) {
                ctx.body = success(data, '筛选成功')
            } else {
                ctx.body = error('没有相关数据')
            }
        } else if (cities && areas) {
            sql += `and cities like "%${cities}%" and areas like "%${areas}%" `
            let data = await query(sql)
            if (data.length) {
                ctx.body = success(data, '筛选成功')
            } else {
                ctx.body = error('没有相关数据')
            }
        } else if (provinces && cities) {
            sql += `and provinces like "%${provinces}%" and cities like "%${cities}%"  `
            let data = await query(sql)
            if (data.length) {
                ctx.body = success(data, '筛选成功')
            } else {
                ctx.body = error('没有相关数据')
            }
        }
    }

}

module.exports = new Results()